package com.thor.palmmall.dao.ipapk;
import java.util.List;
import javax.persistence.Query;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.thor.dao.BasicDao;
import com.thor.palmmall.rest.hdmall.ipapk.MIpapk;
import com.thor.palmmall.rest.hdmall.ipapk.MIpapkType;

@Transactional(rollbackFor = Exception.class, propagation = Propagation.NOT_SUPPORTED)
public class MIpapkDaoImpl extends BasicDao implements MIpapkDao {

	@Override
	public MIpapk getByType(MIpapkType type) {
		if (type == null)
			return null;

		Query query = em.createQuery("from " + PMIpapk.class.getName() + " o where o.type = :type");
		query.setParameter("type", type);
		List<PMIpapk> list = query.getResultList();
		if (list.isEmpty())
			return null;
		PMIpapk ipapk = list.get(0);
		return new MIpapkConverter().convert(ipapk);
	}
}
